package com.company.huisuo.biz.activity

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.viewpager2.widget.ViewPager2.OnPageChangeCallback
import com.company.huisuo.R
import com.company.huisuo.base.BaseActivity
import com.company.huisuo.biz.adapter.ArtistRecommendViewPagerAdapter
import com.company.huisuo.biz.dialog.ArtistTestDialog
import com.company.huisuo.databinding.ActivityArtistRecommendBinding

/**
 * 艺人推荐页面
 */
class ArtistRecommendActivity : BaseActivity<ActivityArtistRecommendBinding>() {

    companion object {
        fun start(activity: AppCompatActivity) {
            activity.startActivity(Intent(activity, ArtistRecommendActivity::class.java))
        }
    }

    override fun initView() {
        mBinding.viewpager.adapter = ArtistRecommendViewPagerAdapter(this)
        mBinding.viewpager.isUserInputEnabled = false
        mBinding.viewpager.registerOnPageChangeCallback(object : OnPageChangeCallback() {
            override fun onPageSelected(position: Int) {
                val isSelectRank = position == 0
                mBinding.tvTabRank.isSelected = isSelectRank
                mBinding.tvTabList.isSelected = !isSelectRank
                val param = mBinding.viewSwitchPoint.layoutParams as ConstraintLayout.LayoutParams
                if (isSelectRank) {
                    param.startToStart = R.id.iv_switch_bg
                    param.endToEnd = ConstraintLayout.LayoutParams.UNSET
                } else {
                    param.startToStart = ConstraintLayout.LayoutParams.UNSET
                    param.endToEnd = R.id.iv_switch_bg
                }
                mBinding.viewSwitchPoint.layoutParams = param
            }
        })
        mBinding.tvTabRank.isSelected = true
        mBinding.tvTabRank.setOnClickListener {
            mBinding.viewpager.currentItem = 0
        }
        mBinding.tvTabList.setOnClickListener {
            mBinding.viewpager.currentItem = 1
        }
        mBinding.ivBack.setOnClickListener {
            finish()
        }
        mBinding.tvSelectedArtist.setOnClickListener {
            ArtistTestDialog(this).show()
        }
    }

    override fun initData() {

    }
}